package com.example.studentpoint.activity

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.studentpoint.R
import com.example.studentpoint.domain.dto.LoginDTO
import com.example.studentpoint.enums.HttpEnums
import com.example.studentpoint.utils.HttpUtils

/**
 * 登陆活动视图
 *
 * @author xxxz
 * {@code @date} 2025-10-25
 */
class LoginActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_login)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 登陆
        findViewById<Button>(R.id.btnLogin).setOnClickListener {
            val username = findViewById<EditText>(R.id.etSNumber).text.toString()
            val password = findViewById<EditText>(R.id.etPassword).text.toString()

            if (username.isBlank() || password.isBlank()) {
                Toast.makeText(this, "请输入学号和密码", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }

            HttpUtils.send(
                HttpEnums.GET.getMethodString(),
                "front/login",
                LoginDTO(
                    username = username,
                    password = password
                )) {
                // todo 登陆成功之后的逻辑
            }
        }
    }
}